解析xml

java解析xml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static List<String> xml2list(InputStream in) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory bdf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = bdf.newDocumentBuilder();
Document document = db.parse(in);
Element root = document.getDocumentElement(); //根节点
NodeList nl = root.getChildNodes();
List<String>ztjlList=new ArrayList<String>();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element&&node.getNodeName().equals("group")) {
Element ele = (Element) node;
ztjlList.add(ele.getAttribute("caption"));
}
}
return ztjlList;
}

js解析xml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* 过滤节点
*/
CoolHTMLWidgetSubPanel.prototype.filterXmlDom = function(xmldom) {
var node=xmldom.children[0];
var caption;
if(g_dwSubjectSet){//酷屏报表
caption=g_dwSubjectSet.caption;
}else{//酷屏门户
caption=dirname;
}
var curNode=$(node).children('group[caption='+caption+']')[0];
while(node.children.length>0){
node.removeChild(node.children[0]);
}
node.appendChild(curNode);
filterNode(curNode);
function filterNode(node){
var children=node.children;
if(children.length>0){
for(var i=0;i<children.length;i++){
var child=children[i];
if(child.tagName=='widget'){
node.removeChild(child);
i--;
}else{
filterNode(child);
}
}
}
}
};